<!DOCTYPE html>
<html lang="en">
<head>
  <title>人事管理系统 ——公告管理</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta http-equiv="pragma" content="no-cache" />
  <meta http-equiv="cache-control" content="no-cache" />
  <meta http-equiv="expires" content="0" />
  <meta http-equiv="keywords" content="keyword1,keyword2,keyword3" />
  <meta http-equiv="description" content="This is my page" />
  <link href="/hrm/css/css.css" type="text/css" rel="stylesheet" />
  <link rel="stylesheet" type="text/css" href="/hrm/js/ligerUI/skins/Aqua/css/ligerui-dialog.css"/>
  <link href="/hrm/js/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
  <script type="text/javascript" src="/hrm/js/jquery-1.11.0.js"></script>
  <script type="text/javascript" src="/hrm/js/jquery-migrate-1.2.1.js"></script>
  <script src="/hrm/js/ligerUI/js/core/base.js" type="text/javascript"></script>
  <script src="/hrm/js/ligerUI/js/plugins/ligerDrag.js" type="text/javascript"></script>
  <script src="/hrm/js/ligerUI/js/plugins/ligerDialog.js" type="text/javascript"></script>
  <script src="/hrm/js/ligerUI/js/plugins/ligerResizable.js" type="text/javascript"></script>
  <link href="/hrm/css/pager.css" type="text/css" rel="stylesheet" />
  <script src="/hrm/js/dayjs.min.js" type="text/javascript"></script>
  <link href="/hrm/css/kkpager_blue.css" type="text/css" rel="stylesheet" />
  <script src="/hrm/js/kkpager.min.js" type="text/javascript"></script>
  <script type="text/javascript">
    function gotoUpdate(id){
      window.location = "/hrm/notice/updateNotice?flag=1&id="+id;
    };
    /** 给全选按钮绑定点击事件  */
    function checkAll(e){
      var boxs  = $("input[type='checkbox'][id^='box_']");
      // this是checkAll  this.checked是true
      // 所有数据行的选中状态与全选的状态一致
      boxs.attr("checked",e.checked);
    }
    $(function(){
      getNoticeList("","",1);
      function getNoticeList(title,content,pageIndex){
        $.ajax({
          url:"/hrm/notice/getNoticeList",
          data:{"pageIndex":pageIndex,"title":title,"content":content},
          type:"POST",
          dataType:"JSON",
          success:function(res){
            if(res && res.notices){
              $("#noticeTable").empty();
              let initHtml = '<tr class="main_trbg_tit" align="center"><td><input type="checkbox" name="checkAll" id="checkAll" onclick="checkAll(this)"></td>';
              initHtml+=' <td>公告名称</td>';
              initHtml+='<td>公告内容</td>';
              initHtml+='<td>创建时间</td>';
              initHtml+='<td>公告人</td>';
              if(parent.user.status == 1){
                initHtml+=' <td>操作</td>';
              }
              //initHtml+='<td>预览</td>';
              initHtml+=' </tr>';
              $("#noticeTable").append(initHtml);
              for (let i = 0; i < res.notices.length; i++) {
                let notice = res.notices[i];
                let html = getTrHtml(notice,i);
                $("#noticeTable").append(html);
              }
              /** 给数据行绑定鼠标覆盖以及鼠标移开事件  */
              $("tr[id^='data_']").hover(function(){
                $(this).css("backgroundColor","#eeccff");
              },function(){
                $(this).css("backgroundColor","#ffffff");
              })
              /** 给预览绑定点击事件 */
              // $("a[id^='prev_']").click(function(){
              //   var noticeId = this.id.replace('prev_','');
              //   localStorage.setItem('noticeId', noticeId);
              //   $.ligerDialog.open({
              //     title:'预览公告',
              //     height: 500,
              //     url: '/hrm/notice/previewNotice?id='+noticeId,
              //     width: 750,
              //     showMax: true,
              //     showToggle: true,
              //     showMin: true,
              //     isResize: true,
              //     slide: false
              //   });
              // })
            }
            if(res && res.pageModel){
              kkpager.generPageHtml({
                pno : pageIndex,
                //总页码
                total : res.pageModel.totalSize,
                //总数据条数
                totalRecords : res.pageModel.recordCount,
                getLink : function(n){
                  console.log(n);
                },
                mode : 'click',//默认值是link，可选link或者click,
                click : function(n){
                  this.selectPage(n);
                  getNoticeList(title,content,n);
                  return false;
                }
              });
            }
          }
        });
      };
      function getTrHtml(notice,index){
        if(notice){
          let html = ' <tr id="data_'+index+'" align="center" class="main_trbg" >';
          html += '<td><input type="checkbox" id="box_'+index+'" value="'+notice.id+'"></td>';
          html+='<td>'+notice.title+'</td>';
          html+='<td>'+notice.content+'</td>';
          let date = dayjs(notice.createDate).format('YYYY-MM-DD') // '25/01/2019'
          html+='<td>'+date+'</td>';
          html+='<td>'+notice.user.username+'</td>';
          if(parent.user.status == 1){
            html +='<td align="center" width="40px;" style="cursor: pointer" onclick="gotoUpdate('+notice.id+')"><img title="修改" src="/hrm/images/update.gif"/></td>'
          }
         // html+='<td align="center"  width="40px;"><a href="#" id="prev_'+notice.id+'"><img title="预览" src="/hrm/images/prev.gif"/></a></td>';
          return html;
        }
      }
      $("#search").click(function(){
        let title = $("#title").val();
        let content = $("#content").val();
        getNoticeList(title,content,1);
      });



      /** 删除公告绑定点击事件 */
      $("#delete").click(function(){
        var boxs  = $("input[type='checkbox'][id^='box_']");
        /** 获取到公告选中的复选框  */
        var checkedBoxs = boxs.filter(":checked");
        if(checkedBoxs.length < 1){
          $.ligerDialog.error("请选择一个需要删除的公告！");
        }else{
          /** 得到公告选中的所有的需要删除的ids */
          var ids = checkedBoxs.map(function(){
            return this.value;
          })

          $.ligerDialog.confirm("确认要删除吗?","删除公告",function(r){
            if(r){
              // alert("删除："+ids.get());
              // 发送请求
              window.location = "/hrm/notice/removeNotice?ids=" + ids.get();
            }
          });
        }
      })


    })
  </script>
</head>
<body>
<!-- 导航 -->
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr><td height="10"></td></tr>
  <tr>
    <td width="15" height="32"><img src="/hrm/images/main_locleft.gif" width="15" height="32"></td>
    <td class="main_locbg font2"><img src="/hrm/images/pointer.gif">&nbsp;&nbsp;&nbsp;当前位置：公告管理 &gt; 公告查询</td>
    <td width="15" height="32"><img src="/hrm/images/main_locright.gif" width="15" height="32"></td>
  </tr>
</table>

<table width="100%" height="90%" border="0" cellpadding="5" cellspacing="0" class="main_tabbor">
  <!-- 查询区  -->
  <tr valign="top">
    <td height="30">
      <table width="100%" border="0" cellpadding="0" cellspacing="10" class="main_tab">
        <tr>
          <td class="fftd">

              <table width="100%" border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td class="font3">
                    公告名称：<input type="text" name="title" id="title">
                    公告内容：<input type="text" name="content" id="content">
                    <input type="submit" value="搜索" id="search"/>
                    <input id="delete" type="button" value="删除"/>
                  </td>
                </tr>
              </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>

  <!-- 数据展示区 -->
  <tr valign="top">
    <td height="20">
      <table width="100%" border="1" cellpadding="5" cellspacing="0" style="border:#c2c6cc 1px solid; border-collapse:collapse;" id="noticeTable">

      </table>
    </td>
  </tr>
  <!-- 分页标签 -->
  <tr valign="top"><td align="center" class="font3">
    <div id="kkpager" ></div>
  </td></tr>
</table>
<div style="height:10px;"></div>
</body>
</html>